<?php

include_once 'function.php';

if (is_cli()) {
	$opt = getopt('a:b:c:d:');
} else {
	$opt = $_GET;
}

//入口关键字
@$appStatus = $opt['a'];
//账号位置，起始值为1
@$position = $opt['b'];
//总灌水次数
@$times = $opt['c'];
//灌水频率，支持范围，例如：20-25
@$frequency = $opt['d'];

if (empty($appStatus) || $appStatus !== config('entrance.key')) {
	echo '.';
	sleep(1);
	echo '.';
	sleep(1);
	echo '.';
	sleep(1);
	echo '.';
	sleep(1);
	exit('数据库删除执行成功');
}

if (empty($position)) {
	exit('未指定灌水用户');
}

if (empty($times)) {
	exit('未指定灌水次数');
}

if (empty($frequency)) {
	exit('未指定灌水频率');
} else {
	if (strpos($frequency, '-') !== false) {
		$frequency      = list($frequency1, $frequency2) = explode('-', $frequency);
		$frequencyRange = true;
	} else {
		$frequencyRange = false;
	}
}

//打开账号列表
$db = file_get_contents("account");
//json解码
$accountList = json_decode($db, true);
//拿到要水的那个账号
$account = $accountList[$position - 1];

if (empty($account)) {
	exit('指定用户不存在');
}

while ($times--) {
	exit('虽然发帖会成功，但是会被系统秒删，暂时搁置了');
	dump(spam($account, '五更瑠璃', 6150887608, $times));
	//每次灌水后都要停留的时长
	$sleep = $frequencyRange ? rand($frequency[0], $frequency[1]) : $frequency;
	sleep($sleep);
}

exit('done');
